<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>项目（客户）列表</title>
    <jsp:include page="../../import.jsp" flush="true"/>
    <!-- 是否显示设置敞口按钮 -->
    <sys:funcAuth resCd="LinkCrAmt">
        <span id="isShowLinkCrAmtBtn"/>
    </sys:funcAuth>
</head>
<body class="iframeBody">
<div class="Wrapper">
    <div id="pageInTab" class="pageInTab">
        <div tabid="tabA" title="项目列表" lselected="true">
            <div class="fieldset1 tabel_col clearFix" id="splPrjPoTab">
                <div class="caption">
                    <span class="title">项目信息汇总</span>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">报单数</div>
                    <div class="field">
                        <span name="prjNum" id="prjNum">&nbsp;</span>
                    </div>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">评审通过数</div>
                    <div class="field">
                        <span name="prjSucNum" id="prjSucNum">&nbsp;</span>
                    </div>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">放款额</div>
                    <div class="field">
                        <span name="payAmt" id="payAmt">&nbsp;</span>
                    </div>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">逾期率</div>
                    <div class="field">
                        <span name="ovdPct" id="ovdPct">&nbsp;</span>
                    </div>
                </div>
            </div>
            <div class="searchArea">
                <form id="searchBar">
                    <div class="fieldset1 clearFix">
                        <div class="fieldBox" id="searchPrjNmId">
                            <div class="label">项目名称</div>
                            <div class="field">
                                <input name="prjNm" id="prjNm" type="text" class="ui-textbox" value="">
                            </div>
                        </div>
                        <div class="fieldBox" id="searchCstNmId">
                            <div class="label">客户名称</div>
                            <div class="field">
                                <input name="cstNm" id="cstNm" type="text" class="ui-textbox" value="">
                            </div>
                        </div>
                        <div class="fieldBox" id="searchLsCntNoId">
                            <div class="label">合同号</div>
                            <div class="field">
                                <input name="lsCntNo" id="lsCntNo" type="text" class="ui-textbox" value="">
                            </div>
                        </div>
                        <div class="clearFix"></div>
                        <div class="btnsBox">
                            <span id="searchBtn" class="sq-button sq-button-round">查询</span>
                            <span id="clearBtn" onclick="clearBtn();" class="sq-button sq-button-round">清空</span>
                            <span id="chooseBtn" onclick="chooseBtn();" class="sq-button sq-button-round">确定</span>
                            <span id="addBtn" onclick="addBtn();" class="sq-button sq-button-round"><!-- <i class="sqBtnIco_3"></i> -->新增</span>
                            <!-- <span id="addBtn" onclick="modifyBtn();" class="sq-button sq-button-hasicon"><i class="sqBtnIco_3"></i>修改</span> -->
                            <!--   <span id="detailBtn" onclick="detailBtn();" class="sq-button sq-button-hasicon"><i class="sqBtnIco_2"></i>详细</span> -->
                            <span id="flowStartBtn" class="sq-button sq-button-round"
                                  onclick="addFlowStart();">发起流程</span>
                            <span id="updateBtn" class="sq-button sq-button-round" style="display:none"
                                  onclick="changeMgr();">业务移交</span>
                            <span id="quaryDelPrjBscInfoList" class="sq-button sq-button-round" style="display:none"
                                  onclick="quaryDelPrjBscInfoList();">项目作废</span>
                            <span id="taskTransfer" class="sq-button sq-button-round" style="display:none"
                                  onclick="taskTransferBtn();">任务交接</span>
                            <span id="compCrLim" class="sq-button sq-button-round" style="display:none"
                                  onclick="addPrjLnkCompCrLim();">设置敞口</span>
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span id="compCrLimText" style="color:red;display:none">当前实际敞口(元)：￥<span>${currCrAmt}</span></span>
                        </div>
                        <div class="pageIn2L_mid" id="templateChange" style="display:none">
                            <form id="import_form">
                                <div class="fieldset1 tabel_col tabel_col_1 clearFix">
                                    <div class="fieldBox col_100">
                                        <div class="label">业务移交</div>
                                        <div class="field">
                                            <jsp:include page="../../system/sysUlFilesRec/sysSysUlFilesRecUpload.jsp"
                                                         flush="true">
                                                <jsp:param name="fileNum" value="1"/>
                                                <jsp:param name="filePath" value="ywchange"/>
                                            </jsp:include>
                                            <span id="addBatchBtn" class="sq-button sq-button-hasicon"
                                                  onclick="addBatch();"><i class="sqBtnIco_33"></i>批量处理</span>
                                            <span id="downTempBtn" class="sq-button sq-button-hasicon"
                                                  onclick="downTemp();"><i class="sqBtnIco_8"></i>下载模板</span>
                                        </div>
                                    </div>
                                </div>
                            </form>
                        </div>
                        <!-- 隐藏客户ID, 提供给客户管理中 项目列表使用 -->
                        <div class="fieldBox col_100" style="display:none;">
                            <div class="field">
                                <input name="cstId" id="cstId" type="text" class="ui-textbox" value="${cstId}">
                                <input name="fromPrjFlagNm" id="fromPrjFlagId" type="text" class="ui-textbox"
                                       value="${fromPrjFlag}">
                                <input name="cstNmNm" id="cstNmId" type="text" class="ui-textbox" value="${cstNm}">
                                <!-- 流程跟踪 隐藏选中数据项目ID -->
                                <input name="projectId" id="projectId" type="text" class="ui-textbox" value="">
                            </div>
                        </div>
                    </div>
                </form>
            </div>

            <div id="ligergrid1" class="sq-grid"></div>
        </div>
        <div tabid="tabB" title="客户列表" lselected="true">
            <iframe frameborder="0" id="cstRskSign" name="cstRskSign" ></iframe>
        </div>

    </div>
</div>


<div id="chooseFlowDIV" style="display:none">
    <div id="ligergrid_flowStart" class="sq-grid"></div>
</div>
<div id="ywchange_result" style="display:none">
    <form id="ywchange_result_form">
    </form>
</div>
<script type="text/javascript">

    var isShowLinkCrAmtBtn = $("#isShowLinkCrAmtBtn");
    var isLnkCompFlag = '${isLnkCompFlag}';
    if (isShowLinkCrAmtBtn.length && isLnkCompFlag && isLnkCompFlag == 1) {
        $("#compCrLim").show();
        $("#compCrLimText").show();
    }

    var grid = null;
    var queryFlag = '${queryFlag}'; //只查询列表
    var updateFlag = '${updateFlag}';//业务移交
    var taskTransfer = '${taskTransfer}';//业务交接
    var updateSunFlag = '${updateSunFlag}';//供应商及账号修改
    var splPrjViewFlag = '${splPrjViewFlag}';//供应商项目页面
    var mgrPrjViewFlag = '${mgrPrjViewFlag}';//客户经理关联项目页面
    var isLnkPrjViewFlag = '${isLnkPrjViewFlag}';//挂靠公司管理项目页面
    var pageInApp = {}; // to 下一级子窗口 接口
    var pageInTab = null;
    $(function () {
        initTab();
        initOrgTree();
        $("#splPrjPoTab").hide();
        if (queryFlag == "query") {
            //隐藏按钮
            $("#addBtn").hide();
            $("#flowStartBtn").hide();
        }
        if (updateFlag == 'update') {
            $("#updateBtn").show();
            $("#templateChange").show();
            $("#quaryDelPrjBscInfoList").show();//项目作废
            pageInTab.removeTabItem("tabB");
        }
        if (updateSunFlag == 'update') {
            pageInTab.removeTabItem("tabB");
        }
        if (taskTransfer == "query") {
            $("#taskTransfer").show();
        }

        //客户ID做为默认查询条件, 提供给客户管理中项目列表使用
        var _cstId = $("#cstId").val();
        var params = "";//默认条件
        if (StringUtils.isNotEmpty(_cstId)) {
            params = "?cstId=" + _cstId
        }
        var lnkCompId = '${lnkCompId}';
        if (StringUtils.isNotEmpty(lnkCompId)) {
            $("#searchPrjStsCdId").hide();
            $("#searchPrjTypCdId").hide();
            $("#searchCstNmId").hide();
            $("#searchBizTypCdId").hide();
            $("#searchCntTypCdId").hide();
            $("#searchInsCodeId").hide();
            //$("#compCrLim").show();
            $("#flowStartBtn").hide();
            $("#addBtn").hide();
        }
        var _splId = '${splId}';
        if (splPrjViewFlag == 'splPrjViewFlag') {
            $('#cstMgrOrgCdId').remove();
            $('#searchCstNmId').remove();
            params = "?ovdViewFlag=ovdViewFlag";
        }
        var _cstMgrId = '${cstMgrId}';
        if (mgrPrjViewFlag == 'mgrPrjViewFlag' && StringUtils.isNotEmpty(_cstMgrId)) {
            $("#searchPrjNmId").remove();
            $("#searchCstNmId").remove();
            $("#searchPrjTypCdId").remove();
            $("#searchBizTypCdId").remove();
            $("#searchPrjStsCdId").remove();
            $("#searchBuOrgCdId").remove();
            $("#searchCstNmId").remove();
            $("#searchCntTypCdId").remove();
            $("#searchLsCntNoId").remove();
            $("#isDelId").remove();
            $('#cstMgrOrgCdId').remove();
            $('#searchCstNmId').remove();
            $("#searchInsCodeId").remove();
            //移除按钮
            $("#searchBtn").remove();
            $("#clearBtn").remove();
            $("#addBtn").remove();
            $("#flowStartBtn").remove();
            params = "?ovdViewFlag=ovdViewFlag&cstMgrId=" + _cstMgrId;
        }
        if (splPrjViewFlag == 'splPrjViewFlag' || mgrPrjViewFlag == 'mgrPrjViewFlag' || '1' == isLnkPrjViewFlag) {
            if (StringUtils.isEmpty(_splId) && StringUtils.isEmpty(_cstMgrId) && StringUtils.isEmpty(lnkCompId)) return;
            $("#splPrjPoTab").show();
            $.ajax({
                type: 'get',
                dataType: 'json',
                data: {
                    splId: _splId,
                    cstMgrId: _cstMgrId,
                    lnkCompId: lnkCompId
                },
                url: '<%=path%>/project/prjbscinfo/getPrjPopuInfo.do',
                success: function (msg) {
                    if (msg.success == 1) {
                        var prjPopuInfo = msg.data.prjPopuInfo;
                        //alert(msg.data.toJSONString());
                        if (prjPopuInfo) {
                            $("#prjNum").html(prjPopuInfo.prjNum);
                            $("#prjSucNum").html(prjPopuInfo.prjSucNum);
                            if (StringUtils.isNotEmpty(prjPopuInfo.payAmt)) {
                                $("#payAmt").html('&yen;' + FormatMoney(prjPopuInfo.payAmt / 100));
                            }
                            $("#ovdPct").html(prjPopuInfo.ovdPct);
                        }
                    }
                }
            });
        }
        $("#ligergrid1").ligerGrid({
            url: '<%=path%>/risk/rskCstSignLog/initPrjList4Rsk.do' + params,
            method: 'get',
            parms: {
                splId: _splId,
                lnkCompId: lnkCompId
            },

            columns: [
                {
                    display: '项目名称', name: 'prjNm', align: 'left', minWidth: 140,
                    render: function (rowdata, rowindex, value, column) {
                        var h = '';
                        if (value && value != "null") {
                            h += '<a href="javascript:detailBtn(';
                            h += "'" + rowdata.id + "'";
                            h += ')">' + value + '</a>'
                        }
                        return h;
                    },
                    enabledSort: true
                },
                {display: '合同号', name: 'lsCntNo', minWidth: 140, enabledSort: true},
                {display: '客户', name: 'cstNm', minWidth: 140, align: 'center', enabledSort: true},
                getOvdDaysColumn(),
                getOvdAmtColumn(),
                {display: '客户经理', name: 'cstMgrNm', minWidth: 140, align: 'center', enabledSort: true},
                {display: '所属机构', name: 'buOrgCdNm', width: 100, enabledSort: true},
                {display: '省公司', name: 'prOrgCdNm', width: 100, enabledSort: true},
                {display: '分公司', name: 'cyOrgCdNm', width: 100, enabledSort: true},
                {display: '项目类型', name: 'prjTypCdNm', width: 150, enabledSort: true},
                {display: '业务模式', name: 'bizTypCdNm', minWidth: 140, enabledSort: true},
                {display: '项目状态', name: 'prjStsCdNm', minWidth: 100, enabledSort: true},
                {display: '机构名称', name: 'fundRasInsNm', minWidth: 150, enabledSort: true},
                {
                    display: '申请单号', name: 'pNo', minWidth: 140,
                    render: function (rowdata, rowindex, value, column) {
                        var h = '';
                        if (value && value != "null") {
                            if (StringUtils.isNotEmpty(rowdata.buOrgCd) && rowdata.buOrgCd == ProjectConstant.CODE_BU_ORG_CD_CAR) {
                                h += '<a href="javascript:commShowFlowForCarBiz(';
                            } else if (StringUtils.isNotEmpty(rowdata.buOrgCd) && rowdata.buOrgCd == ProjectConstant.CODE_BU_ORG_CD_ZC) {
                                if (StringUtils.isNotEmpty(rowdata.cstMgrOrgCd)) {
                                    var orgCd = rowdata.cstMgrOrgCd;
                                    var orgCd_1 = orgCd.substring(0, 12);
                                    if (orgCd_1 == '000000080002') {//专车客车
                                        h += '<a href="javascript:commShowFlowForBusKCBiz(';
                                    } else {
                                        h += '<a href="javascript:commShowFlowForBusBiz(';
                                    }
                                } else {
                                    h += '<a href="javascript:commShowFlowForBusBiz(';
                                }
                            } else {
                                if (rowdata.prjTypCd == 'DSFGHKDCPSZ') {
                                    h += '<a href="javascript:commShowTempFlow(';
                                } else {
                                    h += '<a href="javascript:commShowFlow(';
                                }
                            }
                            h += "'" + rowdata.pInstId + "',";
                            h += "'" + rowdata.prjStsCd + "',";
                            h += "'" + rowdata.id + "'";
                            h += ')">' + value + '</a>'
                        }
                        return h;
                    },
                    enabledSort: true
                },
                {display: '数据来源', name: 'dsCdNm', minWidth: 100, enabledSort: true},
                {display: '创建时间', name: 'crtTm', minWidth: 100, render: renderDate, enabledSort: true},
                getOptColumn()
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -20,
            //isScroll: false,
            checkbox: true,
            delayLoad: true,
            rownumbers: true,
            /* isSingleCheck:true,
            onSelectRow: function(rowdata, rowid, rowobj){
                $("#projectId").val(rowdata.id);
            },
            onUnSelectRow : function(rowdata, rowid, rowobj){
                $("#projectId").val('');
            },
            onAfterShowData : function () {
                SetIframe_height();
            } */
        });
        //   initOrgTree();
        grid = liger.get("ligergrid1");
        grid.setHeight(100);
        grid.options.isSingleCheck = true;
        $("#searchBar").ligerForm();
        $("#searchBtn").click(function (event) {
            var form = new liger.get("searchBar");
            var data = form.getData();
            data["crtTm"] = $("#crtTm").val();
            for (name in data) {
                grid.setParm(name, data[name]);
            }
            ;
            grid.reload();
        });

        var form = new liger.get("searchBar");
        var data = form.getData();
        data["crtTm"] = $("#crtTm").val();
        for (name in data) {
            grid.setParm(name, data[name]);
        }
        ;
        data["splId"] = _splId;
        data["lnkCompId"] = lnkCompId;
        if (StringUtils.isNotEmpty(_cstId)) {
            data["cstId"] = _cstId;
        }
        grid.reload();
        $("#pageloading").hide();
    });


    function initOrgTree() {
        var params = {};
        if (queryFlag == "query") {
            params.userId = '${currentUserId}';
        }
        params.cstMgrOrgCd = '${currOrg}';
        searchOrgTree = $("#cstMgrOrgCd").ligerComboBox({
            width: 480,
            selectBoxWidth: 480,
            selectBoxHeight: 150,
            //限制只能选叶节点，父节点不能点击
            treeLeafOnly: false,
            valueField: 'orgCd',
            textField: 'orgDispNm',
            showTreePath: true,
            tree: {
                ajaxType: 'get',
                idFieldName: 'orgCd',
                textFieldName: 'orgDispNm',
                checkbox: false,
                parentIcon: "none",
                childIcon: "none",
                needCancel: false
            }
        });
        $.ajax({
            type: 'get',
            dataType: 'json',
            data: params,
            url: '<%=path%>/project/prjbscinfo/searchBuOrgTree.do',
            success: function (msg) {
                if (msg.success == 1) {
                    searchOrgTree.treeManager.setData(msg.data);
                    searchOrgTree.clear();
                    searchOrgTree.setValue('${currOrg}');
                } else {
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });

    }

    var loadedTabs = [];

    //初始化Tab页签
    function initTab() {
        pageInTab = $("#pageInTab").ligerTab({
            height: 'auto',
            contextmenu: false,
            minIframeHeight: GET_minIframeHeight(),
            onBeforeSelectTabItem: function (tabid) {
                var selectedRows = grid.getSelectedRows();
                //var projectId = $("#projectId").val();
                if (tabid != "tabA" && tabid != "tabB") {
                    if (selectedRows.length != 1) {
                        $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
                        return false;
                    }
                    /* if(!projectId){
                        $.ligerDialog.SQalert({content: "请选择一条信息！", SQ_type: "warning"});
                        return false;
                    } */
                }
            },
            onAfterSelectTabItem: function (tabid) {
                loadedTabs.push(tabid);
                switch (tabid) {
                    case "tabA":
                        pageInTab.setTabItemSrc(tabid, "<%=path%>/risk/rskCstSignLog/toChoosePrjPage.do");
                        break;
                    case "tabB":
                        pageInTab.setTabItemSrc(tabid, "<%=path%>/risk/rskCstSignLog/toChooseCstPage.do");
                        break;
                }

                SetIframe_height();
            }
        })
        ;
        $.extend(true, pageInApp, {
            pageInTab: pageInTab
        });
    }
    ;

    //获取逾期天数列
    function getOvdDaysColumn() {
        if (splPrjViewFlag == 'splPrjViewFlag' || mgrPrjViewFlag == 'mgrPrjViewFlag') {
            var column = {display: '逾期天数', name: 'ovdDays', minWidth: 80, align: 'center', enabledSort: true};
            return column;
        }
    }

    //获取逾期金额列
    function getOvdAmtColumn() {
        if (splPrjViewFlag == 'splPrjViewFlag' || mgrPrjViewFlag == 'mgrPrjViewFlag') {
            var column = {
                display: '逾期金额', name: '', minWidth: 140, align: 'center', enabledSort: true,
                render: function (rowdata, index, value) {
                    if (StringUtils.isEmpty(rowdata.ovdAmt)) return;
                    return '&yen;' + FormatMoney(rowdata.ovdAmt / 100);
                }
            };
            return column;
        }
    }

    //获取操作列
    function getOptColumn() {
        //添加挂靠公司页面判断 添加敞口页面判断
        if ('1' == isLnkPrjViewFlag || (isShowLinkCrAmtBtn.length && isLnkCompFlag && isLnkCompFlag == 1)) {
            var column = {
                display: '操作',
                isSort: false,
                width: 200,
                align: 'left',
                render: function (rowdata, rowindex, value) {
                    var h = "";
                    h += '<a class="sq-button-hasicon" href="javascript:getscore(';
                    h += "'" + rowdata.id + "'";
                    h += ')"><i class="sqBtnIco_2"></i>评分</a>';
                    return h;
                }
            }
            return column;
        }
        if (queryFlag != "query") {
            var column = {
                display: '操作',
                isSort: false,
                width: 200,
                align: 'left',
                render: function (rowdata, rowindex, value) {
                    var h = "";
                    if (rowdata.prjTypCd == 'CDDYW') {
                        return h;
                    }
                    if (rowdata.isDel != 1) {
                        if ((rowdata.prjStsCd == CommonConstant.C_AUD_NO_HAPPEN_CODE || rowdata.prjStsCd == CommonConstant.C_AUD_NO_PASS_CODE)/* &&
		                	  (rowdata.dsCd!=ProjectConstant.CODE_PRJ_DS_CD_APP) */
                        ) {
                            h += '<a class="sq-button-hasicon" href="javascript:modifyBtn(';
                            h += "'" + rowdata.id + "'";
                            h += ')"><i class="sqBtnIco_4"></i>修改</a>'
                            h += '<a class="sq-button-hasicon" href="javascript:removeBtn(';
                            h += "'" + rowdata.id + "'";
                            h += ')"><i class="sqBtnIco_7"></i>删除</a>'
                        }
                    }
                    /*           h+='<a class="sq-button-hasicon" href="javascript:detailBtn(';
                              h+="'"+rowdata.id+"'";
                              h+=')"><i class="sqBtnIco_2"></i>详情</a>'; */

                    h += '<a class="sq-button-hasicon" href="javascript:getscore(';
                    h += "'" + rowdata.id + "'";
                    h += ')"><i class="sqBtnIco_2"></i>评分</a>';
                    return h;
                }
            }
            return column;
        } else if (updateSunFlag != 'update') {
            var column = {
                display: '操作',
                isSort: false,
                width: 150,
                align: 'left',
                render: function (rowdata, rowindex, value) {
                    var h = "";
                    h += '<a class="sq-button-hasicon" href="javascript:detailBtn(';
                    h += "'" + rowdata.id + "'";
                    h += ')"><i class="sqBtnIco_2"></i>详情</a>';
                    var j = "";
                    j += '<sys:funcAuth resCd="sfshow2604"><a class="sq-button-hasicon" href="javascript:searchCredit(';
                    j += "'" + rowdata.id + "'";
                    j += ')"><i class="sqBtnIco_1"></i>征信查询</a></sys:funcAuth>';
                    return h + j;
                }
            }
            return column;
        } else {
            var column = {
                display: '操作',
                isSort: false,
                width: 200,
                align: 'left',
                render: function (rowdata, rowindex, value) {
                    var h = "";
                    h += '<a class="sq-button-hasicon" href="javascript:updateInfo(';
                    h += "'" + rowdata.id + "'";
                    h += ')"><i class="sqBtnIco_2"></i>供应商修改</a>';
                    h += '<a class="sq-button-hasicon" href="javascript:updateDtl(';
                    h += "'" + rowdata.id + "',";
                    h += "'" + rowdata.buOrgCd + "'";
                    h += ')"><i class="sqBtnIco_2"></i>修改明细</a>';
                    return h;
                }
            }
            return column;
        }
    }

    //显示流程
    function commShowFlow(_pInstId, _audStsCd, _businessKey) {
        if (StringUtils.isEmpty(_pInstId)) {
            UIUtils.alertWarning(CommonConstant.C_P_INSTANCEID_NOT_HERE);
            return;
        }
        var _formUrl = "/project/audit/toAdditionalInfoPage.do?isDetail=1" + "@@processInstanceId=" + _pInstId + "@@projectId=";
        var params = "?pInsId=" + _pInstId + "&status=" + _audStsCd + "&businessKey=" + _businessKey + "&formUrl=" + _formUrl;
        Add_navTab('tab_cst_invoice_flow_' + _businessKey, '查看流程', "<%=path%>/flow/flow/toFlowShowPageFowBus.do" + params);
    }

    //显示流程
    function commShowTempFlow(_pInstId, _audStsCd, _businessKey) {
        if (StringUtils.isEmpty(_pInstId)) {
            UIUtils.alertWarning(CommonConstant.C_P_INSTANCEID_NOT_HERE);
            return;
        }
        var _formUrl = "/project/audit/toTempAdditionalInfoPage.do?isDetail=1" + "@@processInstanceId=" + _pInstId + "@@projectId=";
        var params = "?pInsId=" + _pInstId + "&status=" + _audStsCd + "&businessKey=" + _businessKey + "&formUrl=" + _formUrl;
        Add_navTab('tab_cst_invoice_flow_' + _businessKey, '查看流程', "<%=path%>/flow/flow/toFlowShowPageFowBus.do" + params);
    }

    //乘用车流程
    function commShowFlowForCarBiz(_pInstId, _audStsCd, _businessKey) {
        if (StringUtils.isEmpty(_pInstId)) {
            UIUtils.alertWarning(CommonConstant.C_P_INSTANCEID_NOT_HERE);
            return;
        }
        var _formUrl = "/project/audit/toCarBizAdditionalInfoPage.do?isDetail=1" + "@@processInstanceId=" + _pInstId + "@@projectId=";
        var params = "?pInsId=" + _pInstId + "&status=" + _audStsCd + "&businessKey=" + _businessKey + "&formUrl=" + _formUrl;
        Add_navTab('tab_cst_invoice_flow_' + _businessKey, '查看流程', "<%=path%>/flow/flow/toFlowShowPageFowBus.do" + params);
    }

    //专车以租代购流程
    function commShowFlowForBusBiz(_pInstId, _audStsCd, _businessKey) {
        if (StringUtils.isEmpty(_pInstId)) {
            UIUtils.alertWarning(CommonConstant.C_P_INSTANCEID_NOT_HERE);
            return;
        }
        var _formUrl = "/project/audit/toBusAdditionalInfoPage.do?isDetail=1" + "@@processInstanceId=" + _pInstId + "@@projectId=";
        var params = "?pInsId=" + _pInstId + "&status=" + _audStsCd + "&businessKey=" + _businessKey + "&formUrl=" + _formUrl;
        Add_navTab('tab_cst_invoice_flow_' + _businessKey, '查看流程', "<%=path%>/flow/flow/toFlowShowPageFowBus.do" + params);
    }

    //专车客车流程
    function commShowFlowForBusKCBiz(_pInstId, _audStsCd, _businessKey) {
        if (StringUtils.isEmpty(_pInstId)) {
            UIUtils.alertWarning(CommonConstant.C_P_INSTANCEID_NOT_HERE);
            return;
        }
        var _formUrl = "/project/audit/toBusAdditionalInfoPage.do?isBusKC=1@@isDetail=1" + "@@processInstanceId=" + _pInstId + "@@projectId=";
        var params = "?pInsId=" + _pInstId + "&status=" + _audStsCd + "&businessKey=" + _businessKey + "&formUrl=" + _formUrl;
        Add_navTab('tab_cst_invoice_flow_' + _businessKey, '查看流程', "<%=path%>/flow/flow/toFlowShowPageFowBus.do" + params);
    }

    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr;
    }

    function updateDtl(id, buOrgCd) {
        Add_navTab("prjModify" + id, "修改项目信息", '<%=path%>/project/prjbscinfo/toModifyPage.do?showTabs=tabG&detailFlag=false&ywParam=1&id=' + id + '&buOrgCd=' + buOrgCd);
    }

    function addBtn() {

        var callback = function () {
            grid.reload();
        }
        var fromPrjFlag = true;
        var _flag = $("#fromPrjFlagId").val();//来自哪里
        if (StringUtils.isNotEmpty(_flag)) {
            if (_flag == 'false') {
                fromPrjFlag = false;
            }
        }
        //查询参数
        var params = "?fromPrjFlag=" + fromPrjFlag;

        //如果客户ID存在则加入参数
        var _cstId = $("#cstId").val();//客户ID
        var _cstNm = $("#cstNmId").val();//客户名称
        if (StringUtils.isNotEmpty(_cstId)) {
            params += "&cstId=" + _cstId + "&cstNm=" + _cstNm
        }

        var timestamp = new Date().getTime();
        Add_navTab('tab_prj_bsc_info_add' + timestamp, '添加项目信息', '<%=path%>/project/prjbscinfo/toAddPage.do' + params, callback);
    }

    function modifyBtn(id) {
        var callback = function () {
            grid.reload();
        }
        /* var selectedRows = grid.getSelectedRows();
        if(selectedRows.length != 1){
            $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warring"});
            return;
        } */
        var fromPrjFlag = true;
        var _flag = $("#fromPrjFlagId").val();//来自哪里
        if (StringUtils.isNotEmpty(_flag)) {
            if (_flag == 'false') {
                fromPrjFlag = false;
            }
        }
        //查询参数
        var detailFlag = false;
        var params = "?fromPrjFlag=" + fromPrjFlag + "&id=" + id + "&detailFlag=" + detailFlag;
        //如果客户ID存在则加入参数
        var _cstId = $("#cstId").val();//客户ID
        var _cstNm = $("#cstNmId").val();//客户名称
        if (StringUtils.isNotEmpty(_cstId)) {
            params += "&cstId=" + _cstId + "&cstNm=" + _cstNm
        }
        //var id = selectedRows[0].id;
        Add_navTab('tab_prj_bsc_info_add' + id, '修改项目信息', '<%=path%>/project/prjbscinfo/toModifyPage.do' + params, callback);
    }

    //删除所选项目信息
    function removeBtn(id) {
        var _ids = [];
        _ids.push(id);
        $.ligerDialog.confirm(LogUtils.LOG_CMM_DELETE_CONFIRM, function (flag) {
            if (flag == false) return;
            $.ajax({
                type: 'post',
                dataType: 'json',
                data: {ids: JSON.stringify(_ids)},
                url: '<%=path%>/project/prjbscinfo/removeByIds.do',
                success: function (msg) {
                    if (msg.success == 1) {
                        top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                        grid.reload();
                    } else {
                        top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                }
            });
        });
    }

    function quaryDelPrjBscInfoList() {
        Add_navTab('tab_project_query_list', '项目列表', '<%=path%>/project/prjbscinfo/toPrjBscInfoForDelQuaryListPage.do');
    }

    function detailBtn(id) {
        /* var selectedRows = grid.getSelectedRows();
        if(selectedRows.length != 1){
            $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warring"});
            return;
        }

        var id = selectedRows[0].id; */
        var fromPrjFlag = true;
        var detailFlag = true;

        var _flag = $("#fromPrjFlagId").val();//来自哪里
        if (StringUtils.isNotEmpty(_flag)) {
            if (_flag == 'false') {
                fromPrjFlag = false;
            }
        }

        Add_navTab('tab_project_detail' + id, '项目详情', '<%=path%>/project/prjbscinfo/toModifyPage.do?fromPrjFlag=' + fromPrjFlag + '&&id=' + id + '&&detailFlag=' + detailFlag);
    }

    function searchCredit(_projectId) {
        if (!_projectId) return;
        $.ligerDialog.SQconfirm('确定查询征信吗？', function (yes) {
            if (yes == false) {
                return;
            }
            Add_navTab("toTripartitePage" + _projectId, "人行征信及三方", '<%=path%>/riskctrl/rskctrl/toMainPage.do?id=' + _projectId);
        });
    }

    //启动流程
    function flowStart() {
        var selectedRows = grid.getSelectedRows();
        if (selectedRows.length != 1) {
            $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
            return;
        }
        var prjStsCd = selectedRows[0].prjStsCd;//项目状态
        if (prjStsCd == "1" || prjStsCd == "4") {
            $.ligerDialog.SQalert({content: "项目审核中,不允许多次发起流程.", SQ_type: "warning"});
            return;
        } else if (prjStsCd == "2") {
            $.ligerDialog.SQalert({content: "项目审核通过,不允许再次发起流程.", SQ_type: "warning"});
            return;
        } else if (prjStsCd == "3") {
            $.ligerDialog.SQalert({content: "项目审核不通过,不允许再次发起流程.", SQ_type: "warning"});
            return;
        }
        var modelTyp = FlowConstant.FLOW_MODEL_TYP_PRJ;
        var flowDialog = $.ligerDialog.SQopen({
            url: '<%=path%>/flow/flow/toForStartListPage.do?modelTyp=' + modelTyp,
            width: 700,
            height: 400,
            title: '请选择要发起的流程',
            buttons: [{
                text: "确定", type: 'ok', cls: 'l-dialog-btn-ok',
                onclick: function (item, Dialog) {
                    if (Dialog.onOk) Dialog.onOk();
                }
            }, {
                text: "取消", type: 'cancel', cls: 'l-dialog-btn-no',
                onclick: function (item, Dialog) {
                    if (Dialog.onCancel) Dialog.onCancel();
                }
            }
            ],
            onClose: function () {
                var json = flowDialog._DATA;
                console.log(json);
                if (!json) {
                    return;
                }
                var wait_dialog = $.ligerDialog.SQalert({
                    content: LogUtils.LOG_CMM_DATA_LOADING,
                    SQ_type: "waitting",
                    onClose: function () {
                    }
                });
                var _id = selectedRows[0].id;
                $.ajax({
                    type: 'post',
                    dataType: 'json',
                    data: {
                        id: _id,
                        procDefKey: json.procDefKey,
                        procDefId: json.procDefId,
                        procNo: json.procNo
                    },
                    url: '<%=path%>/project/prjbscinfo/addFlowStart.do',
                    success: function (msg) {
                        wait_dialog.close();
                        if (msg.success == 1) {
                            UIUtils.alertSuccessHold1(msg.info);
                            grid.reload();
                        } else {
                            UIUtils.alertErrorHold1(msg.info);
                        }
                    }
                });
            }
        });
    }

    //2017-4-7 发起流程
    function addFlowStart() {
        var selectedRows = grid.getSelectedRows();
        if (selectedRows.length != 1) {
            $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
            return;
        }
        var prjStsCd = selectedRows[0].prjStsCd;//项目状态
        if (prjStsCd == "1" || prjStsCd == "4") {
            $.ligerDialog.SQalert({content: "项目审核中,不允许多次发起流程.", SQ_type: "warning"});
            return;
        } else if (prjStsCd == "2") {
            $.ligerDialog.SQalert({content: "项目审核通过,不允许再次发起流程.", SQ_type: "warning"});
            return;
        } else if (prjStsCd == "3") {
            $.ligerDialog.SQalert({content: "项目审核不通过,不允许再次发起流程.", SQ_type: "warning"});
            return;
        }

        var prjTypCd = selectedRows[0].prjTypCd;//项目类型
        if ('CDDYW' === prjTypCd) {
            $.ligerDialog.SQalert({content: "车抵贷业务不支持手动发起流程.", SQ_type: "warning"});
            return;
        }

        //发起流程确认  2017-6-8 by YAOXIURONG
        $.ligerDialog.confirm(FlowConstant.FLOW_ADD_START_CONFIRM, function (flag) {
            if (flag == false) {
                wait_dialog.close();
                return;
            }
            ;
            var prjId = selectedRows[0].id;
            var wait_dialog = $.ligerDialog.SQalert({
                content: LogUtils.LOG_CMM_DATA_LOADING,
                SQ_type: "waitting",
                onClose: function () {
                }
            });
            var isOk = true;//是否验证通过
            //浙商校验四要素是否验证通过
            if (selectedRows[0].insCode == 'czbank') {
                $.ajax({
                    type: 'get',
                    dataType: 'json',
                    async: false,
                    url: '<%=path%> /project/prjCstAccInfo/searchAccInfoByPrjId.do?prjId=' + selectedRows[0].id,
                    success: function (data) {
                        if (data.success != 1) {
                            wait_dialog.close();
                            $.ligerDialog.SQalert({content: data.info, SQ_type: "error", SQ_showButtons: true});
                            isOk = false;
                        }
                    }
                });
            }
            //浦发开户状态检验
            if (selectedRows[0].insCode == 'spdbank') {
                $.ajax({
                    type: 'get',
                    dataType: 'json',
                    async: false,
                    url: ' /project/prjCstAccInfo/checkInsAcc.do?prjId=' + selectedRows[0].id,
                    success: function (data) {
                        if (data.success != 1) {
                            wait_dialog.close();
                            $.ligerDialog.SQalert({content: data.info, SQ_type: "error", SQ_showButtons: true});
                            isOk = false;
                        }
                    }
                });
            }
            //判断是否验证通过
            if (!isOk) {
                return;
            }

            $.ajax({
                type: 'post',
                dataType: 'json',
                url: '<%=path%>/project/audit/lnkCompAud.do?prjId=' + prjId,
                success: function (data) {
                    if (data.success == 1) {
                        $.ajax({
                            type: 'post',
                            dataType: 'json',
                            url: '<%=path%>/project/audit/addFlowStart.do?prjId=' + prjId,
                            success: function (msg) {
                                wait_dialog.close();
                                if (msg.success == 1) {//成功发起流程
                                    //UIUtils.alertSuccessHold1(msg.info);
                                    var url = '<%=path%>/flow/flow/getFlowNextAssigne.do?key=' + msg.data;
                                    FlowUtils.alertNextFlowAssign(url);
                                    grid.reload();
                                } else if (msg.success == 0) {//错误
                                    UIUtils.alertErrorHold1(msg.info);
                                } else if (msg.success == 2) {//找到多个流程
                                    //TODO
                                    console.log(msg.data);
                                    var __DATA_radioList = msg.data;
                                    var selectedVal = '';
                                    var selectDialog = $.ligerDialog.SQopen({
                                        width: 300,
                                        height: 200,
                                        title: '请选择要发起的流程',
                                        allowClose: false,
                                        content: '<div id="radiolist1"></div>',
                                        fixButtons: true, //固定按钮到底部
                                        onOk: function () {
                                            console.log(selectDialog);
                                            console.log(selectedVal);
                                            if (StringUtils.isEmpty(selectedVal)) {
                                                $.ligerDialog.SQalert({content: "请选择要发起的流程.", SQ_type: "warning"});
                                                return;
                                            } else {
                                                selectDialog.close();
                                                var wait_dialog = $.ligerDialog.SQalert({
                                                    content: LogUtils.LOG_CMM_DATA_LOADING,
                                                    SQ_type: "waitting",
                                                    onClose: function () {
                                                    }
                                                });
                                                $.ajax({
                                                    type: 'post',
                                                    dataType: 'json',
                                                    url: '<%=path%>/project/audit/addFlowStart.do?prjId=' + prjId + '&procDefKey=' + selectedVal,
                                                    success: function (msg) {
                                                        wait_dialog.close();
                                                        if (msg.success == 1) {//成功发起流程
                                                            //UIUtils.alertSuccessHold1(msg.info);
                                                            var url = '<%=path%>/flow/flow/getFlowNextAssigne.do?key=' + msg.data;
                                                            FlowUtils.alertNextFlowAssign(url);
                                                            grid.reload();
                                                        } else if (msg.success == 0) {//错误
                                                            UIUtils.alertErrorHold1(msg.info);
                                                        }
                                                    }
                                                })
                                            }
                                        }
                                    });
                                    $("#radiolist1").ligerRadioList({
                                        data: __DATA_radioList,
                                        textField: 'procNm',
                                        valueField: 'procDefKey',
                                        rowSize: 1,
                                        onSelect: function (data) {
                                            console.log(data);
                                            selectedVal = data.value;
                                        }
                                    });
                                }
                            }
                        });
                    } else {
                        wait_dialog.close();
                        $.ligerDialog.SQalert({content: data.info, SQ_type: "warning"});
                        return;
                    }
                }
            });
        });
    }

    function changeMgr() {
        var callback = function () {
            grid.reload();
        }
        var selectedRows = grid.getSelectedRows();
        if (selectedRows.length == 0) {
            $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW, SQ_type: "warning"});
            return;
        }
        var ids = "";
        for (var index in selectedRows) {
            ids = ids + selectedRows[index].id + ",";
        }
        $.ligerDialog.open({
            title: '业务移交',
            height: 500,
            width: 850,
            url: '<%=path%>/project/prjbscinfo/changeMgr.do?ids=' + ids,
            callback: callback
        });
    }

    //下载模板
    function downTemp() {
        window.location.href = "<%=path%>/resource/template/ywchange/ywchange.xlsx";
    }

    //批量导入
    function addBatch() {
        //获取上传文件地址
        var files = getUploadResultParams();
        if (files && files.length > 0) {
            var filePath = files[0].filePath;
            var fileExtension = filePath.substring(filePath.lastIndexOf('.') + 1);
            if (fileExtension != 'xlsx' && fileExtension != 'XLSX') {
                $.ligerDialog.SQalert({content: "请上传.xlsx后缀的文件", SQ_type: "warn"});
                return;
            }
            var wait_dialog;
            $.ajax({
                type: 'post',
                dataType: 'json',
                data: "filePath=" + filePath,
                url: '<%=path%>/project/prjbscinfo/ywchange.do',
                beforeSend: function () {
                    wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
                },
                success: function (msg) {
                    wait_dialog.close();
                    if (msg.success == 1) {
                        if (msg.data.length > 0) {
                            showResult(msg.data);
                        } else {
                            $.ligerDialog.SQalert({content: "处理成功！", SQ_type: "success"});
                            clearUploadResultParams();
                        }
                    } else {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                }
            });
        } else {
            $.ligerDialog.SQalert({content: "请先上传文件", SQ_type: "warn"});
        }
    }

    function showResult(data) {
        $.ligerDialog.SQopen({
            width: 400,
            top: 100,
            buttons: [
                {
                    text: "关闭", cls: 'l-dialog-btn-no', onclick: function () {
                        $.ligerDialog.hide();
                    }
                }
            ],
            title: '业务移交结果',
            target: $("#ywchange_result")
        });
        $("#ywchange_result_form").ligerForm({
            validate: true
        });
        $("#ywchange_result_form").html("");
        //填充数据(动态展示数据)
        for (var i = 0; i < data.length; i++) {
            var lsCntNo = data[i].lsCntNo;
            var usrNm = data[i].usrNm;
            var p = '<p><span>' + lsCntNo + '</span><span style="margin-left:100px">' + usrNm + '</span></p>';
            $("#ywchange_result_form").append(p);
        }
        clearUploadResultParams();
    }

    function updateInfo(id) {
        var callback = function () {
            grid.reload();
        }
        var detailFlag = true;
        Add_navTab('tab_prj_prd_info_pro_change' + id, '供应商修改', '<%=path%>/project/prjbscinfo/toPrjPrdListPage.do?id=' + id + '&detailFlag=' + detailFlag + '&changeFlag=0', callback);
        //$.ligerDialog.open({  title: '供应商修改',height: 600,width: 850, url:'<%=path%>/project/prjbscinfo/toPrjPrdListPage.do?id='+id+'&detailFlag='+detailFlag+'&changeFlag=0',callback:callback});
        //$.ligerDialog.open({  title: '供应商修改',height: 200,width: 740, url:'<%=path%>/project/prjbscinfo/changePro.do?id='+id,callback:callback});
    }

    //初始化查询条件中的下拉树
    /*var searchOrgTree = null;
      function initOrgTree(){
           searchOrgTree = $("#orgCd").ligerComboBox({
               selectBoxWidth: 240,
               selectBoxHeight: 150,
               treeLeafOnly: false, //限制只能选叶节点，父节点不能点击
               tree: {
                   ajaxType: 'get',
                   idFieldName:'text',
                   checkbox: false,
                   parentIcon: "none",
                   childIcon: "none"
               }
           });

           $.ajax({
               type: 'get',
               dataType:'json',
               data: "",
               url: '<%=path%>/system/sysOrg/searchOrgTree.do',
     		success:function(msg){
     			if(msg.success == 1){
     				searchOrgTree.treeManager.setData(msg.data);
     				searchOrgTree.clear();
     			}else{
     				 $.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
     			}
     		}
     	});

    }*/
    function clearBtn() {
        $("#searchBar").ligerForm();
        var form = new liger.get("searchBar");
        //form.clear();
        form.setData({
            prjNm: " ",
            cstNm: " ",
            prjTypCd: " ",
            bizTypCd: " ",
            prjStsCd: " ",
            orgCd: " ",
            lsCntNo: " ",
            cstMgrNm: "",
            cntTypCd: " "
        });
    }

    function iframeResize() {
        if (parent.mainApp) {
            parent.mainApp.parentTab.onResize();
        }
    }

    function getscore(prjId) {
        //弹出框校验供应商是否已存在
        $.ligerDialog.SQopen({
            width: 1000,
            height: 480,
            title: '',
            url: '<%=path%>/system/sysscorerec/toGetPrjScore.do?id=' + prjId,

        });
    }

    function addPrjLnkCompCrLim(lnkCompId) {
        var lnkCompId = '${lnkCompId}';
        $.ligerDialog.open({
            title: '添加挂靠公司敞口信息',
            height: 400,
            width: 900,
            url: '<%=path%>/project/prjlnkcomp/toAddPrjLnkCompCrLimPage.do?lnkCompId=' + lnkCompId,
            buttons: [{
                text: "保存", onclick: onSave, type: 'ok', cls: 'l-dialog-btn-ok'
            },
                {
                    text: "取消", onclick: onCancel, type: 'cancel', cls: 'l-dialog-btn-no'
                }
            ]
        });
    }

    var onSave = function (item, Dialog) {
        //在子页面里绑定 frameElement.dialog.onOk = function () {}
        if (Dialog.onSave) Dialog.onSave();
    };

    var onCancel = function (item, Dialog) {
        //在子页面里绑定 frameElement.dialog.onOk = function () {}
        if (Dialog.onCancel) Dialog.onCancel();
    };

    function taskTransferBtn() {

        $.ligerDialog.open({
            title: '任务交接',
            height: 600,
            width: 1000,
            url: '<%=path%>/project/prjbscinfo/taskTransfer.do'
        });
    }

    function chooseBtn() {
        var selectedRows = grid.getSelectedRows();
        if (selectedRows.length != 1) {
            $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
            return;
        }
        if (selectedRows == '') {
            alert("必须选择一条项目数据");
        } else if (selectedRows.length != 1) {
            alert("只能选择一条项目数据");
        } else {
            var prjId = selectedRows[0].id;
            Add_navTab('tab_rsk_add' + prjId, '风险标记', '<%=path%>/risk/rskCstSignLog/toAddCstPrjPage.do?prjId=' + prjId);
            // window.location.href = '<%=path%>/risk/rskCstSignLog/toAddPage.do?prjId='+prjId;
        }
    }
</script>

</body>
</html>